package io.renren.modules.emp.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.emp.entity.EmployeeLocationEntity;
import io.renren.modules.matlist.entity.MatlistEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import io.renren.modules.emp.entity.EmployeeEntity;
import io.renren.modules.emp.service.EmployeeService;
import io.renren.common.utils.R;
@RestController
@RequestMapping("emp/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/list")
    @RequiresPermissions("emp:employee:list")
    public R list(@RequestParam Map<String, Object> params){
       // PageUtils page = employeeService.queryPage(params);
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String eid = String.valueOf(params.get("key"));
        Page<EmployeeEntity> page = new Page<>(pageIndex,pageSize);
        // 通过调用自定义dao层实现
        employeeService.selectByEmployeeid(eid,page);
        return R.ok().put("page", page);
    }

    @GetMapping(value = "/num",produces = {"application/json;charset=UTF-8"})
    public List listNum(){
        return employeeService.listNum();
    }

    @RequestMapping("/info/{employeeId}")
    @RequiresPermissions("emp:employee:info")
    public R info(@PathVariable("employeeId") Integer employeeId){
		EmployeeEntity employee = employeeService.getById(employeeId);
        return R.ok().put("employee", employee);
    }

    @RequestMapping("/save")
    @RequiresPermissions("emp:employee:save")
    public R save(@RequestBody EmployeeEntity employee){
		employeeService.save(employee);
        return R.ok();
    }

    @RequestMapping("/update")
    @RequiresPermissions("emp:employee:update")
    public R update(@RequestBody EmployeeEntity employee){
		employeeService.updateById(employee);
        return R.ok();
    }

    @RequestMapping("/delete")
    @RequiresPermissions("emp:employee:delete")
    public R delete(@RequestBody Integer[] employeeNos){
		employeeService.removeByIds(Arrays.asList(employeeNos));
        return R.ok();
    }

////    查询坐标
//    @GetMapping("getLocation")
//    public List<EmployeeLocationEntity> getLocation(@RequestParam("eid") String eid){
//        return employeeService.getLocation(eid);
//    }
    //查询坐标
    @GetMapping("getLocation")
    public R getLocation(@RequestParam Map<String, Object> params){
        // PageUtils page = employeeService.queryPage(params);
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String eid = String.valueOf(params.get("eid"));
        Page<EmployeeLocationEntity> page = new Page<>(pageIndex,pageSize);
        // 通过调用自定义dao层实现
        employeeService.getLocation(eid,page);
        return R.ok().put("page", page);
    }

}
